local ma__shedi = fk.CreateSkill{
  name = "ma__shedi",
}

Fk:loadTranslationTable{
  ["ma__shedi"] = "慑敌",
  [":ma__shedi"] = "每回合限一次，其他角色使用【杀】指定你为目标后，你可以弃置手牌中所有的【杀】并对其造成1点伤害。此【杀】结算后，若你未受到此牌伤害，你将手牌摸至体力上限。",

  ["#ma__shedi-invoke"] = "慑敌：你可以弃置所有【杀】，对 %dest 造成1点伤害",  
}

ma__shedi:addEffect(fk.TargetSpecified, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return target ~= player and player:hasSkill(ma__shedi.name) and data.firstTarget and
      table.contains(data.use.tos, player) and data.card.trueName == "slash" and 
      player:usedSkillTimes(ma__shedi.name, Player.HistoryTurn) == 0
  end,
  on_cost = function (self, event, target, player, data)
    local slashs = table.filter(player:getCardIds("h"), function(id)
        return Fk:getCardById(id).trueName == "slash"
      end)
    player.room:askToSkillInvoke(player, {
      skill_name = self.name,
      prompt = "#ma__shedi-invoke::"..data.from.id,
    })
    if #slashs > 0 then
      event:setCostData(self, {cards = slashs})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = event:getCostData(self).cards
    room:throwCard(cards, ma__shedi.name, player, player)
      if not data.from.dead then
        room:damage{
          from = player,
          to = data.from,
          damage = 1,
          skillName = ma__shedi.name,
        }
      end
    data.extra_data = data.extra_data or {}
    data.extra_data.ma__shedi = {player}
  end,
})

ma__shedi:addEffect(fk.CardUseFinished, {
  mute = true,
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    return data.card.trueName == "slash" and
      data.extra_data and data.extra_data.ma__shedi and data.extra_data.ma__shedi[1] == player and
      not (data.damageDealt and data.damageDealt[player])
  end,
  on_use = function(self, event, target, player, data)
    local target_num = player.maxHp
    local cur_num = player:getHandcardNum()
    if cur_num < target_num then
      player:drawCards(math.min(target_num - cur_num, 20), ma__shedi.name)
    end
  end,
})

return ma__shedi